@extends("layouts.backend.webadmin")
@section('page-header')
    <h1>
        <small>falw\menu</small>
    </h1>
@endsection

@section('content')
    <style>
        #cate_id{
            width:100%;}
    </style>
    <link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2.min.css">
    <link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2totree.css">
    <link href="{{env('APP_ROOT')}}/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
    <script src="{{env('APP_ROOT')}}/js/fileinput.min.js"></script>
    <script src="{{env('APP_ROOT')}}/js/fileinput.zh.min.js"></script>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        @if($errors->any())
                            <ul class="alert alert-danger">
                                @foreach($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        @endif
                        @if($action =='add')
                            <form action="{{ URL::route('admin.goods.goodsadd') }}" method="POST" enctype="multipart/form-data">
                                @elseif($action =='update')
                                    <form action="{{ URL::route('admin.goods.goodsupdate') }}" enctype="multipart/form-data" method="POST">
                                        <input type="hidden" name="id" value="{{$item->id}}">
                                        @endif
                                        <div class="form-group">
                                            <label for="picture">商品名称</label>
                                            <input type="text" class="form-control" id="picture" placeholder="商品名称"
                                                   name="name"
                                                   @if($action =='update')value="{{$item->name}} @else value="{{old('name')}}" @endif">
                                        </div>
                                        <div class="form-group">
                                            <label for="cate_id">商品分类</label>
                                            <select class="form-control select2"   id="cate_id" name="cate_id">
                                            <option value="">所有</option>
                                            @foreach($gclist as $category)
                                                <option class="l{{$category->num}} {{$category->child=='yes'?'non-leaf':''}}" data-pup="{{$category->pid}}" value="{{$category->id}}"  @if(($action =='update' || $action =='detail') && $category->id == $item->cate_id) selected @endif >{{$category->name}}</option>
                                            @endforeach
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="description">描述</label>
                                            <input type="text" class="form-control" id="description" placeholder="描述" name="description" @if($action =='update')value="{{$item->description}}" @else value="{{old('description')}}" @endif>
                                        </div>
                                        <div class="form-group">
                                            <label for="picture">商品图片</label>
                                            <input type="file" class="form-control file" id="input-b1" placeholder="商品图片"
                                                   name="picture"
                                                   @if($action =='update')value="{{$item->picture}} @else value="{{old('picture')}}" @endif">
                                        </div>
                                        <div class="form-group">
                                            <label for="price">商品价格</label>
                                            <input type="text" class="form-control" id="price" placeholder="商品价格"
                                                   name="price"
                                                   @if($action =='update')value="{{$item->price}} @else value="{{old('price')}}" @endif">
                                        </div>
                                        <div class="form-group">
                                            <label for="stock">库存</label>
                                            <input type="text" class="form-control" id="stock" placeholder="库存"
                                                   name="stock"
                                                   @if($action =='update')value="{{$item->stock}} @else value="{{old('stock')}}" @endif">
                                        </div>
                                        <div class="form-group">
                                            <label for="on_sale">是否上架</label>
                                            <select class="form-control" id="on_sale" name="on_sale">
                                                <option value="1" @if(($action =='update' || $action =='detail') && 1 == $item->on_sale) selected @endif >是</option>
                                                <option value="0" @if(($action =='update' || $action =='detail') && 0 == $item->on_sale) selected @endif >否</option>
                                            </select>
                                        </div>
                                        <div class="form-group form_datetime">
                                            <label for="is_recommented">是否推荐</label>
                                            <select class="form-control" id="is_recommented" name="is_recommented">
                                                <option value="0" @if(($action =='update' || $action =='detail') && 0 == $item->is_recommented) selected @endif >否</option>
                                                <option value="1" @if(($action =='update' || $action =='detail') && 1 == $item->is_recommented) selected @endif >是</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label>详情</label>
                            <textarea class="form-control" rows="3" placeholder="相关描述..."
                                      name="content"> @if($action =='update'){{$item->content}} @else {{old('content')}} @endif</textarea>
                                        </div>
                                        {!! csrf_field() !!}
                                        @if($action =='add')
                                            <button type="submit" class="btn btn-default">添加</button>
                                        @else
                                            <button type="submit" class="btn btn-default">更新</button>
                                        @endif
                                    </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
@stop
@section('javascript-end')
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2.min.js"></script>
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2totree.js"></script>
    <script>
        $(function(){
            $('#cate_id').select2ToTree({"border-radius":'0px', width: '100%' });
        });
        $("#input-b1").fileinput({
            language: "zh",
            showUpload: false,
//            maxFileCount: 5,/*设置按钮大小*/
//            mainClass: "input-group-lg",/*设置按钮类名*/
            allowedFileExtensions: ["jpg", "png", "gif"]
//            browseClass: "btn btn-primary btn-block",/*单排显示*/
//            showCaption: false/*禁用input*/
        });
    </script>
@endsection